﻿using LD.Host;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace LD
{
    public partial class FrmWelcome : Form
    {
        private System.Timers.Timer m_Timer;
        public FrmWelcome()
        {
            InitializeComponent();
            Shown += FrmWelcome_Shown;
            m_Timer = new System.Timers.Timer(100);

        }

        private void FrmWelcome_Shown(object sender, EventArgs e)
        {
            m_Timer.Elapsed += M_Timer_Elapsed;
            m_Timer.AutoReset = false;
            m_Timer.Start();
        }

        private void M_Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            //初始化参数
            ProgressUpdate(5);
            TextUpdate("初始化参数");
            AppLoader.InitUser();
            ProgressUpdate(10);
            AppLoader.InitVariable();
            ProgressUpdate(15);

            //加载所有信息
            TextUpdate("加载机种信息");
            AppLoader.LoadPartNo();
            ProgressUpdate(20);

            ProgressUpdate(30);

            ProgressUpdate(40);

            TextUpdate("加载机种流程");
            ProgressUpdate(50);

            TextUpdate("加载通讯信息");
            AppLoader.LoadHD();
            ProgressUpdate(60);

            TextUpdate("加载板卡信息");
            //AppLoader.LoadBc();  //移至主界面
            ProgressUpdate(70);

            TextUpdate("加载相机信息");
            AppLoader.LoadCCD();
            ProgressUpdate(80);

            ProgressUpdate(100);

            Loading = true;
        }

        private void TextUpdate(string msg)
        {
            this.Invoke(new Action(() =>
                lab_loadText.Text = msg
            ));
        }
        private void ProgressUpdate(int val)
        {
            this.Invoke(new Action(() =>
                progressBarY1.Value = val
            ));
        }
        public bool Loading { get; private set; }

    }
}
